from django.db import models


# 类别
class Category(models.Model):
    cname = models.CharField(max_length=10)

    def __str__(self):
        return self.cname


# 商品明细
class Goods(models.Model):
    gname = models.CharField(max_length=100)
    gdesc = models.CharField(max_length=100)
    oldprice = models.DecimalField(max_digits=5,decimal_places=2)
    price = models.DecimalField(max_digits=5,decimal_places=2)
    category = models.ForeignKey(Category,on_delete=models.CASCADE)

    def __str__(self):
        return self.gname


# 商品详情名称
class GoodsDetailName(models.Model):
    gdname = models.CharField(max_length=100)

    def __str__(self):
        return self.gdname

# 商品详情
class GoodsDetail(models.Model):
    gdurl = models.ImageField(upload_to='')
    gdname = models.ForeignKey(GoodsDetailName,on_delete=models.CASCADE)
    goods = models.ForeignKey(Goods,on_delete=models.CASCADE)


# 商品颜色
class Color(models.Model):
    colorname = models.CharField(max_length=10)
    colorurl = models.ImageField(upload_to='color/')

    def __str__(self):
        return self.colorname


# 商品大小
class Size(models.Model):
    sname = models.CharField(max_length=10)

    def __str__(self):
        return self.sname

# 商品存货
class Inventory(models.Model):
    count = models.PositiveIntegerField()
    color = models.ForeignKey(Color,on_delete=models.CASCADE)
    goods = models.ForeignKey(Goods,on_delete=models.CASCADE)
    size  = models.ForeignKey(Size,on_delete=models.CASCADE)

    